********************************************************************************
** 	TITLE:		ca2000_ces_contact_networks                                   **
**	AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       ces2000                                                       **
**	DATE:		October 2022 					                              **	
**	VERSION:	Stata 16					                                  **
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close
log using "ca2000_ces_contact_networks", replace

* Open dataset

use "ces2000.dta", clear


**************************
** RELABELING DISTRICTS **
**************************

label define district 10001 "Bonavista--Trinity--Conception" 10002 "Burin--St. George's" 10003 "Gander--Grand Falls" 10004 "Humber--St. Barbe--Baie Verte" 10005 "Labrador" 10006 "St. John's East" 10007 "St. John's West" 11001 "Cardigan" 11002 "Egmont" 11003 "Hillsborough" 11004 "Malpeque" 12001 "Bras d'Or" 12002 "Cumberland--Colchester" 12003 "Dartmouth" 12004 "Halifax" 12005 "Halifax West" 12006 "Kings--Hants" 12007 "Pictou--Antigonish--Guysborough" 12008 "Sackville--Eastern Shore" 12009 "South Shore" 12010 "Sydney--Victoria" 12011 "West Nova" 13001 "Acadie--Bathurst" 13002 "Beausejour--Petitcodiac" 13003 "Charlotte" 13004 "Fredericton" 13005 "Fundy--Royal" 13006 "Madawaska--Restigouche" 13007 "Miramichi" 13008 "Moncton" 13009 "Saint John" 13010 "Tobique--Mactaquac" 24001 "Abitibi" 24002 "Ahuntsic" 24003 "Anjou--RiviÞre-des-Prairies" 24004 "Argenteuil--Papineau" 24005 "Beauce" 24006 "Beauharnois--Salaberry" 24007 "Beauport--Montmorency--Orleans" 24008 "Bellechasse--Etchemins--Montmagny--L'Islet" 24009 "Berthier--Montcalm" 24010 "Bourassa" 24011 "Brome--Missisquoi" 24012 "Brossard--La Prairie" 24013 "Chambly" 24014 "Champlain" 24015 "Charlesbourg" 24016 "Charlevoix" 24017 "Chateauguay" 24018 "Chicoutimi" 24019 "Compton--Stanstead" 24020 "Drummond" 24021 "Frontenac--Megantic" 24022 "Bonaventure--Gaspe--Iles-de-la-Madeleine--Pabok" 24023 "Gatineau" 24024 "Hochelaga--Maisonneuve" 24025 "Hull--Aylmer" 24026 "Joliette" 24027 "Jonquiere" 24028 "Kamouraska--RiviÞre-du-Loup--Temiscouata--Les Basques" 24029 "Notre-Dame-de-Grace--Lachine" 24030 "Lac-Saint-Jean" 24031 "Lac-Saint-Louis" 24032 "LaSalle--Emard" 24033 "Laurentides" 24034 "Laurier--Sainte-Marie" 24035 "Laval Centre" 24036 "Laval East" 24037 "Laval West" 24038 "Levis" 24039 "Longueuil" 24040 "Lotbiniere" 24041 "Louis-Hebert" 24042 "Manicouagan" 24043 "Matapedia--Matane" 24044 "Mercier" 24045 "Mount Royal" 24046 "Outremont" 24047 "Papineau--Saint-Denis" 24048 "Pierrefonds--Dollard" 24049 "Pontiac--Gatineau--Labelle" 24050 "Portneuf" 24051 "Quebec" 24052 "Quebec East" 24053 "Repentigny" 24054 "Richelieu" 24055 "Richmond--Arthabaska" 24056 "Rimouski--Mitis" 24057 "Roberval" 24058 "Rosemont" 24059 "Temiscamingue" 24060 "Saint-Eustache--Sainte-Therese" 24061 "Saint-Bruno--Saint-Hubert" 24062 "Saint-Hyacinthe--Bagot" 24063 "Saint-Jean" 24064 "Saint-Lambert" 24065 "Saint-Laurent--Cartierville" 24066 "Saint-Leonard--Saint-Michel" 24067 "Saint-Maurice" 24068 "Shefford" 24069 "Sherbrooke" 24070 "Terrebonne--Blainville" 24071 "Trois-Rivieres" 24072 "Vaudreuil--Soulanges" 24073 "Vercheres" 24074 "Verdun--Saint-Henri" 24075 "Westmount--Ville-Marie" 35001 "Algoma--Manitoulin" 35002 "Barrie--Simcoe--Bradford" 35003 "Beaches--East York" 35004 "Bramalea--Gore--Malton" 35005 "Brampton Centre" 35006 "Brampton West--Mississauga" 35007 "Brant" 35008 "Broadview--Greenwood" 35009 "Bruce--Grey" 35010 "Burlington" 35011 "Cambridge" 35012 "Davenport" 35013 "Don Valley East" 35014 "Don Valley West" 35015 "Dufferin--Peel--Wellington--Grey" 35016 "Durham" 35017 "Eglinton--Lawrence" 35018 "Elgin--Middlesex--London" 35019 "Erie--Lincoln" 35020 "Essex" 35021 "Etobicoke Centre" 35022 "Etobicoke--Lakeshore" 35023 "Etobicoke North" 35024 "Glengarry--Prescott--Russell" 35025 "Carleton--Gloucester" 35026 "Guelph--Wellington" 35027 "Haldimand--Norfolk--Brant" 35028 "Halton" 35029 "Hamilton East" 35030 "Hamilton Mountain" 35031 "Hamilton West" 35032 "Hastings--Frontenac--Lennox and Addington" 35033 "Huron--Bruce" 35034 "Kenora--Rainy River" 35035 "Kent--Essex" 35036 "Kingston and the Islands" 35037 "Kitchener Centre" 35038 "Kitchener--Waterloo" 35039 "Lambton--Kent--Middlesex" 35040 "Lanark--Carleton" 35041 "Leeds--Grenville" 35042 "London North Centre" 35043 "London--Fanshawe" 35044 "London West" 35045 "Markham" 35046 "Mississauga Centre" 35047 "Mississauga East" 35048 "Mississauga South" 35049 "Mississauga West" 35050 "Nepean--Carleton" 35051 "Niagara Centre" 35052 "Niagara Falls" 35053 "Nickel Belt" 35054 "Nipissing" 35055 "Northumberland" 35056 "Oak Ridges" 35057 "Oakville" 35058 "Oshawa" 35059 "Ottawa Centre" 35060 "Ottawa South" 35061 "Ottawa--Vanier" 35062 "Ottawa West--Nepean" 35063 "Oxford" 35064 "Parkdale--High Park" 35065 "Parry Sound--Muskoka" 35066 "Perth--Middlesex" 35067 "Peterborough" 35068 "Pickering--Ajax--Uxbridge" 35069 "Prince Edward--Hastings" 35070 "Renfrew--Nipissing--Pembroke" 35071 "Sarnia--Lambton" 35072 "Sault Ste. Marie" 35073 "Scarborough--Agincourt" 35074 "Scarborough Centre" 35075 "Scarborough East" 35076 "Scarborough--Rouge River" 35077 "Scarborough Southwest" 35078 "Simcoe--Grey" 35079 "Simcoe North" 35080 "St. Catharines" 35081 "St. Paul's" 35082 "Stoney Creek" 35083 "Stormont--Dundas" 35084 "Sudbury" 35085 "Thornhill" 35086 "Thunder Bay--Atikokan" 35087 "Thunder Bay--Nipigon" 35088 "Timiskaming--Cochrane" 35089 "Timmins--James Bay" 35090 "Toronto Centre--Rosedale" 35091 "Trinity--Spadina" 35092 "Vaughan--King--Aurora" 35093 "Victoria--Haliburton" 35094 "Waterloo--Wellington" 35095 "Wentworth--Burlington" 35096 "Whitby--Ajax" 35097 "Willowdale" 35098 "Windsor--St. Clair" 35099 "Windsor West" 35100 "York Centre" 35101 "York North" 35102 "York South--Weston" 35103 "York West" 46001 "Brandon--Souris" 46002 "Charleswood--Assiniboine" 46003 "Churchill" 46004 "Dauphin--Swan River" 46005 "Portage--Lisgar" 46006 "Provencher" 46007 "Saint Boniface" 46008 "Selkirk--Interlake" 46009 "Winnipeg North Centre" 46010 "Winnipeg Centre" 46011 "Winnipeg South" 46012 "Winnipeg South Centre" 46013 "Winnipeg North--St. Paul" 46014 "Winnipeg--Transcona" 47001 "Battlefords--Lloydminster" 47002 "Blackstrap" 47003 "Churchill River" 47004 "Cypress Hills--Grasslands" 47005 "Palliser" 47006 "Prince Albert" 47007 "Qu'Appelle" 47008 "Regina--Lumsden--Lake Centre" 47009 "Saskatoon--Humboldt" 47010 "Saskatoon--Rosetown--Biggar" 47011 "Souris--Moose Mountain" 47012 "Wanuskewin" 47013 "Wascana" 47014 "Yorkton--Melville" 48001 "Athabasca" 48002 "Calgary Centre" 48003 "Calgary East" 48004 "Calgary Northeast" 48005 "Calgary--Nose Hill" 48006 "Calgary Southeast" 48007 "Calgary Southwest" 48008 "Calgary West" 48009 "Crowfoot" 48010 "Edmonton East" 48011 "Edmonton North" 48012 "Edmonton Southeast" 48013 "Edmonton Southwest" 48014 "Edmonton--Strathcona" 48015 "Edmonton West" 48016 "Elk Island" 48017 "Lakeland" 48018 "Lethbridge" 48019 "Macleod" 48020 "Medicine Hat" 48021 "Peace River" 48022 "Red Deer" 48023 "St. Albert" 48024 "Wetaskiwin" 48025 "Wild Rose" 48026 "Yellowhead" 59001 "Burnaby--Douglas" 59002 "Cariboo--Chilcotin" 59003 "Delta--South Richmond" 59004 "Dewdney--Alouette" 59005 "Esquimalt--Juan de Fuca" 59006 "Fraser Valley" 59007 "Kamloops" 59008 "Kelowna" 59009 "Kootenay--Columbia" 59010 "Langley--Abbotsford" 59011 "Nanaimo--Alberni" 59012 "Nanaimo--Cowichan" 59013 "New Westminster--Coquitlam--Burnaby" 59014 "Okanagan--Shuswap" 59015 "North Vancouver" 59016 "Okanagan--Coquihalla" 59017 "Port Moody--Coquitlam" 59018 "Prince George--Bulkley Valley" 59019 "Prince George--Peace River" 59020 "Richmond" 59021 "Saanich--Gulf Islands" 59022 "Skeena" 59023 "South Surrey--White Rock--Langley" 59024 "Surrey Central" 59025 "Surrey North" 59026 "Vancouver Centre" 59027 "Vancouver East" 59028 "Vancouver Island North" 59029 "Vancouver Kingsway" 59030 "Vancouver Quadra" 59031 "Vancouver South--Burnaby" 59032 "Victoria" 59033 "West Kootenay--Okanagan" 59034 "West Vancouver--Sunshine Coast" 60001 "Yukon" 61001 "Nunavut" 61002 "Western Arctic" 62001 "Nunavut"

label values fed96 district


*****************************
** DISTRICT-LEVEL OUTCOMES **
*****************************

* Note: 1 = LPC, 2 = BQ, 3 = Reform/Alliance, 4 = PC, 5 = NDP, 97 = other

gen district_outcome = .

replace district_outcome = 1 if fed96 == 10001
replace district_outcome = 4 if fed96 == 10002
replace district_outcome = 1 if fed96 == 10003
replace district_outcome = 1 if fed96 == 10004
replace district_outcome = 1 if fed96 == 10005
replace district_outcome = 4 if fed96 == 10006
replace district_outcome = 4 if fed96 == 10007
replace district_outcome = 1 if fed96 == 11001
replace district_outcome = 1 if fed96 == 11002
replace district_outcome = 1 if fed96 == 11003
replace district_outcome = 1 if fed96 == 11004
replace district_outcome = 5 if fed96 == 12001
replace district_outcome = 4 if fed96 == 12002
replace district_outcome = 5 if fed96 == 12003
replace district_outcome = 5 if fed96 == 12004
replace district_outcome = 5 if fed96 == 12005
replace district_outcome = 4 if fed96 == 12006
replace district_outcome = 4 if fed96 == 12007
replace district_outcome = 5 if fed96 == 12008
replace district_outcome = 4 if fed96 == 12009
replace district_outcome = 5 if fed96 == 12010
replace district_outcome = 4 if fed96 == 12011
replace district_outcome = 5 if fed96 == 13001
replace district_outcome = 5 if fed96 == 13002
replace district_outcome = 4 if fed96 == 13003
replace district_outcome = 1 if fed96 == 13004
replace district_outcome = 4 if fed96 == 13005
replace district_outcome = 4 if fed96 == 13006
replace district_outcome = 1 if fed96 == 13007
replace district_outcome = 1 if fed96 == 13008
replace district_outcome = 4 if fed96 == 13009
replace district_outcome = 4 if fed96 == 13010
replace district_outcome = 1 if fed96 == 24001
replace district_outcome = 1 if fed96 == 24002
replace district_outcome = 1 if fed96 == 24003
replace district_outcome = 2 if fed96 == 24004
replace district_outcome = 1 if fed96 == 24005
replace district_outcome = 2 if fed96 == 24006
replace district_outcome = 2 if fed96 == 24007
replace district_outcome = 1 if fed96 == 24008
replace district_outcome = 2 if fed96 == 24009
replace district_outcome = 1 if fed96 == 24010
replace district_outcome = 1 if fed96 == 24011
replace district_outcome = 1 if fed96 == 24012
replace district_outcome = 2 if fed96 == 24013
replace district_outcome = 2 if fed96 == 24014
replace district_outcome = 2 if fed96 == 24015
replace district_outcome = 2 if fed96 == 24016
replace district_outcome = 2 if fed96 == 24017
replace district_outcome = 4 if fed96 == 24018
replace district_outcome = 4 if fed96 == 24019
replace district_outcome = 2 if fed96 == 24020
replace district_outcome = 2 if fed96 == 24021
replace district_outcome = 2 if fed96 == 24022
replace district_outcome = 1 if fed96 == 24023
replace district_outcome = 2 if fed96 == 24024
replace district_outcome = 1 if fed96 == 24025
replace district_outcome = 2 if fed96 == 24026
replace district_outcome = 2 if fed96 == 24027
replace district_outcome = 2 if fed96 == 24028
replace district_outcome = 1 if fed96 == 24029
replace district_outcome = 2 if fed96 == 24030
replace district_outcome = 1 if fed96 == 24031
replace district_outcome = 1 if fed96 == 24032
replace district_outcome = 2 if fed96 == 24033
replace district_outcome = 2 if fed96 == 24034
replace district_outcome = 2 if fed96 == 24035
replace district_outcome = 2 if fed96 == 24036
replace district_outcome = 1 if fed96 == 24037
replace district_outcome = 2 if fed96 == 24038
replace district_outcome = 2 if fed96 == 24039
replace district_outcome = 2 if fed96 == 24040
replace district_outcome = 2 if fed96 == 24041
replace district_outcome = 2 if fed96 == 24042
replace district_outcome = 2 if fed96 == 24043
replace district_outcome = 2 if fed96 == 24044
replace district_outcome = 1 if fed96 == 24045
replace district_outcome = 1 if fed96 == 24046
replace district_outcome = 1 if fed96 == 24047
replace district_outcome = 1 if fed96 == 24048
replace district_outcome = 1 if fed96 == 24049
replace district_outcome = 2 if fed96 == 24050
replace district_outcome = 2 if fed96 == 24051
replace district_outcome = 2 if fed96 == 24052
replace district_outcome = 2 if fed96 == 24053
replace district_outcome = 2 if fed96 == 24054
replace district_outcome = 4 if fed96 == 24055
replace district_outcome = 2 if fed96 == 24056
replace district_outcome = 2 if fed96 == 24057
replace district_outcome = 2 if fed96 == 24058
replace district_outcome = 2 if fed96 == 24059
replace district_outcome = 2 if fed96 == 24060
replace district_outcome = 2 if fed96 == 24061
replace district_outcome = 2 if fed96 == 24062
replace district_outcome = 2 if fed96 == 24063
replace district_outcome = 1 if fed96 == 24064
replace district_outcome = 1 if fed96 == 24065
replace district_outcome = 1 if fed96 == 24066
replace district_outcome = 1 if fed96 == 24067
replace district_outcome = 4 if fed96 == 24068
replace district_outcome = 4 if fed96 == 24069
replace district_outcome = 2 if fed96 == 24070
replace district_outcome = 2 if fed96 == 24071
replace district_outcome = 1 if fed96 == 24072
replace district_outcome = 2 if fed96 == 24073
replace district_outcome = 1 if fed96 == 24074
replace district_outcome = 1 if fed96 == 24075
replace district_outcome = 1 if fed96 == 35001
replace district_outcome = 1 if fed96 == 35002
replace district_outcome = 1 if fed96 == 35003
replace district_outcome = 1 if fed96 == 35004
replace district_outcome = 1 if fed96 == 35005
replace district_outcome = 1 if fed96 == 35006
replace district_outcome = 1 if fed96 == 35007
replace district_outcome = 1 if fed96 == 35008
replace district_outcome = 1 if fed96 == 35009
replace district_outcome = 1 if fed96 == 35010
replace district_outcome = 1 if fed96 == 35011
replace district_outcome = 1 if fed96 == 35012
replace district_outcome = 1 if fed96 == 35013
replace district_outcome = 1 if fed96 == 35014
replace district_outcome = 1 if fed96 == 35015
replace district_outcome = 1 if fed96 == 35016
replace district_outcome = 1 if fed96 == 35017
replace district_outcome = 1 if fed96 == 35018
replace district_outcome = 1 if fed96 == 35019
replace district_outcome = 1 if fed96 == 35020
replace district_outcome = 1 if fed96 == 35021
replace district_outcome = 1 if fed96 == 35022
replace district_outcome = 1 if fed96 == 35023
replace district_outcome = 1 if fed96 == 35024
replace district_outcome = 1 if fed96 == 35025
replace district_outcome = 1 if fed96 == 35026
replace district_outcome = 1 if fed96 == 35027
replace district_outcome = 1 if fed96 == 35028
replace district_outcome = 1 if fed96 == 35029
replace district_outcome = 1 if fed96 == 35030
replace district_outcome = 1 if fed96 == 35031
replace district_outcome = 1 if fed96 == 35032
replace district_outcome = 1 if fed96 == 35033
replace district_outcome = 1 if fed96 == 35034
replace district_outcome = 1 if fed96 == 35035
replace district_outcome = 1 if fed96 == 35036
replace district_outcome = 1 if fed96 == 35037
replace district_outcome = 1 if fed96 == 35038
replace district_outcome = 1 if fed96 == 35039
replace district_outcome = 1 if fed96 == 35040
replace district_outcome = 1 if fed96 == 35041
replace district_outcome = 1 if fed96 == 35042
replace district_outcome = 1 if fed96 == 35043
replace district_outcome = 1 if fed96 == 35044
replace district_outcome = 4 if fed96 == 35045
replace district_outcome = 1 if fed96 == 35046
replace district_outcome = 1 if fed96 == 35047
replace district_outcome = 1 if fed96 == 35048
replace district_outcome = 1 if fed96 == 35049
replace district_outcome = 1 if fed96 == 35050
replace district_outcome = 1 if fed96 == 35051
replace district_outcome = 1 if fed96 == 35052
replace district_outcome = 1 if fed96 == 35053
replace district_outcome = 1 if fed96 == 35054
replace district_outcome = 1 if fed96 == 35055
replace district_outcome = 1 if fed96 == 35056
replace district_outcome = 1 if fed96 == 35057
replace district_outcome = 1 if fed96 == 35058
replace district_outcome = 1 if fed96 == 35059
replace district_outcome = 1 if fed96 == 35060
replace district_outcome = 1 if fed96 == 35061
replace district_outcome = 1 if fed96 == 35062
replace district_outcome = 1 if fed96 == 35063
replace district_outcome = 1 if fed96 == 35064
replace district_outcome = 1 if fed96 == 35065
replace district_outcome = 1 if fed96 == 35066
replace district_outcome = 1 if fed96 == 35067
replace district_outcome = 1 if fed96 == 35068
replace district_outcome = 1 if fed96 == 35069
replace district_outcome = 1 if fed96 == 35070
replace district_outcome = 1 if fed96 == 35071
replace district_outcome = 1 if fed96 == 35072
replace district_outcome = 1 if fed96 == 35073
replace district_outcome = 1 if fed96 == 35074
replace district_outcome = 1 if fed96 == 35075
replace district_outcome = 1 if fed96 == 35076
replace district_outcome = 1 if fed96 == 35077
replace district_outcome = 1 if fed96 == 35078
replace district_outcome = 1 if fed96 == 35079
replace district_outcome = 1 if fed96 == 35080
replace district_outcome = 1 if fed96 == 35081
replace district_outcome = 1 if fed96 == 35082
replace district_outcome = 1 if fed96 == 35083
replace district_outcome = 1 if fed96 == 35084
replace district_outcome = 1 if fed96 == 35085
replace district_outcome = 1 if fed96 == 35086
replace district_outcome = 1 if fed96 == 35087
replace district_outcome = 1 if fed96 == 35088
replace district_outcome = 1 if fed96 == 35089
replace district_outcome = 1 if fed96 == 35090
replace district_outcome = 1 if fed96 == 35091
replace district_outcome = 1 if fed96 == 35092
replace district_outcome = 1 if fed96 == 35093
replace district_outcome = 1 if fed96 == 35094
replace district_outcome = 1 if fed96 == 35095
replace district_outcome = 1 if fed96 == 35096
replace district_outcome = 1 if fed96 == 35097
replace district_outcome = 1 if fed96 == 35098
replace district_outcome = 1 if fed96 == 35099
replace district_outcome = 1 if fed96 == 35100
replace district_outcome = 1 if fed96 == 35101
replace district_outcome = 97 if fed96 == 35102
replace district_outcome = 1 if fed96 == 35103
replace district_outcome = 4 if fed96 == 46001
replace district_outcome = 1 if fed96 == 46002
replace district_outcome = 5 if fed96 == 46003
replace district_outcome = 3 if fed96 == 46004
replace district_outcome = 3 if fed96 == 46005
replace district_outcome = 1 if fed96 == 46006
replace district_outcome = 1 if fed96 == 46007
replace district_outcome = 3 if fed96 == 46008
replace district_outcome = 5 if fed96 == 46009
replace district_outcome = 5 if fed96 == 46010
replace district_outcome = 1 if fed96 == 46011
replace district_outcome = 1 if fed96 == 46012
replace district_outcome = 1 if fed96 == 46013
replace district_outcome = 5 if fed96 == 46014
replace district_outcome = 3 if fed96 == 47001
replace district_outcome = 3 if fed96 == 47002
replace district_outcome = 5 if fed96 == 47003
replace district_outcome = 3 if fed96 == 47004
replace district_outcome = 5 if fed96 == 47005
replace district_outcome = 3 if fed96 == 47006
replace district_outcome = 5 if fed96 == 47007
replace district_outcome = 5 if fed96 == 47008
replace district_outcome = 3 if fed96 == 47009
replace district_outcome = 5 if fed96 == 47010
replace district_outcome = 3 if fed96 == 47011
replace district_outcome = 3 if fed96 == 47012
replace district_outcome = 1 if fed96 == 47013
replace district_outcome = 3 if fed96 == 47014
replace district_outcome = 3 if fed96 == 48001
replace district_outcome = 3 if fed96 == 48002
replace district_outcome = 3 if fed96 == 48003
replace district_outcome = 3 if fed96 == 48004
replace district_outcome = 3 if fed96 == 48005
replace district_outcome = 3 if fed96 == 48006
replace district_outcome = 3 if fed96 == 48007
replace district_outcome = 3 if fed96 == 48008
replace district_outcome = 3 if fed96 == 48009
replace district_outcome = 3 if fed96 == 48010
replace district_outcome = 3 if fed96 == 48011
replace district_outcome = 1 if fed96 == 48012
replace district_outcome = 3 if fed96 == 48013
replace district_outcome = 3 if fed96 == 48014
replace district_outcome = 1 if fed96 == 48015
replace district_outcome = 3 if fed96 == 48016
replace district_outcome = 3 if fed96 == 48017
replace district_outcome = 3 if fed96 == 48018
replace district_outcome = 3 if fed96 == 48019
replace district_outcome = 3 if fed96 == 48020
replace district_outcome = 3 if fed96 == 48021
replace district_outcome = 3 if fed96 == 48022
replace district_outcome = 3 if fed96 == 48023
replace district_outcome = 3 if fed96 == 48024
replace district_outcome = 3 if fed96 == 48025
replace district_outcome = 3 if fed96 == 48026
replace district_outcome = 5 if fed96 == 59001
replace district_outcome = 3 if fed96 == 59002
replace district_outcome = 3 if fed96 == 59003
replace district_outcome = 3 if fed96 == 59004
replace district_outcome = 3 if fed96 == 59005
replace district_outcome = 3 if fed96 == 59006
replace district_outcome = 5 if fed96 == 59007
replace district_outcome = 3 if fed96 == 59008
replace district_outcome = 3 if fed96 == 59009
replace district_outcome = 3 if fed96 == 59010
replace district_outcome = 3 if fed96 == 59011
replace district_outcome = 3 if fed96 == 59012
replace district_outcome = 3 if fed96 == 59013
replace district_outcome = 3 if fed96 == 59014
replace district_outcome = 3 if fed96 == 59015
replace district_outcome = 3 if fed96 == 59016
replace district_outcome = 3 if fed96 == 59017
replace district_outcome = 3 if fed96 == 59018
replace district_outcome = 3 if fed96 == 59019
replace district_outcome = 1 if fed96 == 59020
replace district_outcome = 3 if fed96 == 59021
replace district_outcome = 3 if fed96 == 59022
replace district_outcome = 3 if fed96 == 59023
replace district_outcome = 3 if fed96 == 59024
replace district_outcome = 3 if fed96 == 59025
replace district_outcome = 1 if fed96 == 59026
replace district_outcome = 5 if fed96 == 59027
replace district_outcome = 3 if fed96 == 59028
replace district_outcome = 1 if fed96 == 59029
replace district_outcome = 1 if fed96 == 59030
replace district_outcome = 1 if fed96 == 59031
replace district_outcome = 1 if fed96 == 59032
replace district_outcome = 3 if fed96 == 59033
replace district_outcome = 3 if fed96 == 59034
replace district_outcome = 5 if fed96 == 60001
replace district_outcome = 1 if fed96 == 61001
replace district_outcome = 1 if fed96 == 61002
replace district_outcome = 1 if fed96 == 62001


*********************
** COMPETITIVENESS **
*********************

* Margin of victory by district

gen margin = .

replace margin = 27.28 if fed96 == 10001
replace margin = 21.84 if fed96 == 10002
replace margin = 26.63 if fed96 == 10003
replace margin = 22.39 if fed96 == 10004
replace margin = 56.61 if fed96 == 10005
replace margin = 22.03 if fed96 == 10006
replace margin = 20.61 if fed96 == 10007
replace margin = 1.550003 if fed96 == 11001
replace margin = 11.45 if fed96 == 11002
replace margin = 11.31 if fed96 == 11003
replace margin = 9.68 if fed96 == 11004
replace margin = 33.47 if fed96 == 12001
replace margin = 21.88 if fed96 == 12002
replace margin = 3.139999 if fed96 == 12003
replace margin = 7.369999 if fed96 == 12004
replace margin = 9.219999 if fed96 == 12005
replace margin = 10.06 if fed96 == 12006
replace margin = 16.84 if fed96 == 12007
replace margin = 1.919998 if fed96 == 12008
replace margin = 4.57 if fed96 == 12009
replace margin = 13.3 if fed96 == 12010
replace margin = 1.98 if fed96 == 12011
replace margin = 6.34 if fed96 == 13001
replace margin = 14.99 if fed96 == 13002
replace margin = 19.72 if fed96 == 13003
replace margin = 8.869999 if fed96 == 13004
replace margin = 10.23 if fed96 == 13005
replace margin = 14.43 if fed96 == 13006
replace margin = 26.27 if fed96 == 13007
replace margin = 40.75 if fed96 == 13008
replace margin = 21.94 if fed96 == 13009
replace margin = .4599991 if fed96 == 13010
replace margin = 7.230003 if fed96 == 24001
replace margin = 21.66 if fed96 == 24002
replace margin = 27.51 if fed96 == 24003
replace margin = 1.080002 if fed96 == 24004
replace margin = 29.5 if fed96 == 24005
replace margin = 5.869999 if fed96 == 24006
replace margin = 5.119999 if fed96 == 24007
replace margin = 10.47 if fed96 == 24008
replace margin = 27.01 if fed96 == 24009
replace margin = 34.15 if fed96 == 24010
replace margin = 19.09 if fed96 == 24011
replace margin = 19.75 if fed96 == 24012
replace margin = 16.63 if fed96 == 24013
replace margin = .0299988 if fed96 == 24014
replace margin = 1.440002 if fed96 == 24015
replace margin = 33.51 if fed96 == 24016
replace margin = 5.939999 if fed96 == 24017
replace margin = 12.07 if fed96 == 24018
replace margin = 7.670002 if fed96 == 24019
replace margin = 11.06 if fed96 == 24020
replace margin = 3.68 if fed96 == 24021
replace margin = 10.19 if fed96 == 24022
replace margin = 26.05 if fed96 == 24023
replace margin = 11.82 if fed96 == 24024
replace margin = 28.32 if fed96 == 24025
replace margin = 19.44 if fed96 == 24026
replace margin = 14.27 if fed96 == 24027
replace margin = 29.65 if fed96 == 24028
replace margin = 42.61 if fed96 == 24029
replace margin = 42.86 if fed96 == 24030
replace margin = 66.64001 if fed96 == 24031
replace margin = 41.55 if fed96 == 24032
replace margin = 11.05 if fed96 == 24033
replace margin = 27.04 if fed96 == 24034
replace margin = .079998 if fed96 == 24035
replace margin = 2.220001 if fed96 == 24036
replace margin = 19.03 if fed96 == 24037
replace margin = 7.73 if fed96 == 24038
replace margin = 19.72 if fed96 == 24039
replace margin = 8.290001 if fed96 == 24040
replace margin = 4.259998 if fed96 == 24041
replace margin = 17.56 if fed96 == 24042
replace margin = .8800011 if fed96 == 24043
replace margin = 19.94 if fed96 == 24044
replace margin = 75.13 if fed96 == 24045
replace margin = 19.39 if fed96 == 24046
replace margin = 27.5 if fed96 == 24047
replace margin = 61.86 if fed96 == 24048
replace margin = 13.3 if fed96 == 24049
replace margin = 5.549999 if fed96 == 24050
replace margin = 7.950001 if fed96 == 24051
replace margin = 1.139999 if fed96 == 24052
replace margin = 30.92 if fed96 == 24053
replace margin = 25.88 if fed96 == 24054
replace margin = .7299995 if fed96 == 24055
replace margin = 30.03 if fed96 == 24056
replace margin = 20.32 if fed96 == 24057
replace margin = 15.3 if fed96 == 24058
replace margin = 7.389999 if fed96 == 24059
replace margin = 15.01 if fed96 == 24060
replace margin = 4.899998 if fed96 == 24061
replace margin = 20.64 if fed96 == 24062
replace margin = 11.35 if fed96 == 24063
replace margin = 7.290001 if fed96 == 24064
replace margin = 60.51 if fed96 == 24065
replace margin = 62.19 if fed96 == 24066
replace margin = 15.11 if fed96 == 24067
replace margin = 1.98 if fed96 == 24068
replace margin = 4.689999 if fed96 == 24069
replace margin = 20.21 if fed96 == 24070
replace margin = 3.75 if fed96 == 24071
replace margin = 17.07 if fed96 == 24072
replace margin = 21.79 if fed96 == 24073
replace margin = 21.9 if fed96 == 24074
replace margin = 48.21 if fed96 == 24075
replace margin = 19.37 if fed96 == 35001
replace margin = 15.98 if fed96 == 35002
replace margin = 31.81 if fed96 == 35003
replace margin = 38.27 if fed96 == 35004
replace margin = 25.19 if fed96 == 35005
replace margin = 49.99 if fed96 == 35006
replace margin = 30.74 if fed96 == 35007
replace margin = 24.25 if fed96 == 35008
replace margin = 8.610001 if fed96 == 35009
replace margin = 22.51 if fed96 == 35010
replace margin = 15.22 if fed96 == 35011
replace margin = 53.16 if fed96 == 35012
replace margin = 52.09 if fed96 == 35013
replace margin = 32.23 if fed96 == 35014
replace margin = 13.98 if fed96 == 35015
replace margin = 15.05 if fed96 == 35016
replace margin = 43.42 if fed96 == 35017
replace margin = 4.07 if fed96 == 35018
replace margin = 5.099998 if fed96 == 35019
replace margin = 9.730003 if fed96 == 35020
replace margin = 34.07 if fed96 == 35021
replace margin = 30.67 if fed96 == 35022
replace margin = 53.03 if fed96 == 35023
replace margin = 49.26 if fed96 == 35024
replace margin = 25.51 if fed96 == 35025
replace margin = 28.07 if fed96 == 35026
replace margin = 12.23 if fed96 == 35027
replace margin = 21 if fed96 == 35028
replace margin = 33.43 if fed96 == 35029
replace margin = 29.18 if fed96 == 35030
replace margin = 34.64 if fed96 == 35031
replace margin = 8.65 if fed96 == 35032
replace margin = 25.95 if fed96 == 35033
replace margin = 16.59 if fed96 == 35034
replace margin = 17.64 if fed96 == 35035
replace margin = 33.67 if fed96 == 35036
replace margin = 26.76 if fed96 == 35037
replace margin = 27.33 if fed96 == 35038
replace margin = 18.12 if fed96 == 35039
replace margin = 2.939999 if fed96 == 35040
replace margin = .1199989 if fed96 == 35041
replace margin = 31 if fed96 == 35042
replace margin = 32.53 if fed96 == 35043
replace margin = 28.28 if fed96 == 35044
replace margin = 47.93 if fed96 == 35045
replace margin = 46.66 if fed96 == 35046
replace margin = 48.86 if fed96 == 35047
replace margin = 26.38 if fed96 == 35048
replace margin = 41.8 if fed96 == 35049
replace margin = 3.790001 if fed96 == 35050
replace margin = 17.6 if fed96 == 35051
replace margin = 15.15 if fed96 == 35052
replace margin = 34.41 if fed96 == 35053
replace margin = 34.51 if fed96 == 35054
replace margin = 19.85 if fed96 == 35055
replace margin = 38.36 if fed96 == 35056
replace margin = 19.72 if fed96 == 35057
replace margin = 14.1 if fed96 == 35058
replace margin = 16.2 if fed96 == 35059
replace margin = 26.85 if fed96 == 35060
replace margin = 39.77 if fed96 == 35061
replace margin = 15.05 if fed96 == 35062
replace margin = 4.99 if fed96 == 35063
replace margin = 30.42 if fed96 == 35064
replace margin = 22.13 if fed96 == 35065
replace margin = 12.93 if fed96 == 35066
replace margin = 19.87 if fed96 == 35067
replace margin = 33.65 if fed96 == 35068
replace margin = 26.03 if fed96 == 35069
replace margin = 5.18 if fed96 == 35070
replace margin = 21.41 if fed96 == 35071
replace margin = 26.02 if fed96 == 35072
replace margin = 57.49 if fed96 == 35073
replace margin = 45.36 if fed96 == 35074
replace margin = 40.99 if fed96 == 35075
replace margin = 70.12 if fed96 == 35076
replace margin = 45.33 if fed96 == 35077
replace margin = 12.31 if fed96 == 35078
replace margin = 21.18 if fed96 == 35079
replace margin = 10.96 if fed96 == 35080
replace margin = 32.5 if fed96 == 35081
replace margin = 22.83 if fed96 == 35082
replace margin = 7.239998 if fed96 == 35083
replace margin = 39.62 if fed96 == 35084
replace margin = 48.79 if fed96 == 35085
replace margin = 7.689999 if fed96 == 35086
replace margin = 28.3 if fed96 == 35087
replace margin = 43.62 if fed96 == 35088
replace margin = 23.07 if fed96 == 35089
replace margin = 38.12 if fed96 == 35090
replace margin = 9.57 if fed96 == 35091
replace margin = 50.05 if fed96 == 35092
replace margin = 2.27 if fed96 == 35093
replace margin = 10.73 if fed96 == 35094
replace margin = 9.610001 if fed96 == 35095
replace margin = 25.7 if fed96 == 35096
replace margin = 44.48 if fed96 == 35097
replace margin = .9700012 if fed96 == 35098
replace margin = 31.25 if fed96 == 35099
replace margin = 57.85 if fed96 == 35100
replace margin = 21.91 if fed96 == 35101
replace margin = 4.309998 if fed96 == 35102
replace margin = 66.59 if fed96 == 35103
replace margin = 5.539999 if fed96 == 46001
replace margin = 6.07 if fed96 == 46002
replace margin = 12.71 if fed96 == 46003
replace margin = 26.34 if fed96 == 46004
replace margin = 32.49 if fed96 == 46005
replace margin = 17.14 if fed96 == 46006
replace margin = 28.99 if fed96 == 46007
replace margin = 20.23 if fed96 == 46008
replace margin = 30.92 if fed96 == 46009
replace margin = 7.149998 if fed96 == 46010
replace margin = 20.9 if fed96 == 46011
replace margin = 12.1 if fed96 == 46012
replace margin = 8.379999 if fed96 == 46013
replace margin = 22.41 if fed96 == 46014
replace margin = 42.84 if fed96 == 47001
replace margin = 17.88 if fed96 == 47002
replace margin = 9.240002 if fed96 == 47003
replace margin = 44.74 if fed96 == 47004
replace margin = .6599998 if fed96 == 47005
replace margin = 24.82 if fed96 == 47006
replace margin = .579998 if fed96 == 47007
replace margin = .5399971 if fed96 == 47008
replace margin = 17.85 if fed96 == 47009
replace margin = .25 if fed96 == 47010
replace margin = 47.67 if fed96 == 47011
replace margin = 28.34 if fed96 == 47012
replace margin = 5.07 if fed96 == 47013
replace margin = 46.74 if fed96 == 47014
replace margin = 26.06 if fed96 == 48001
replace margin = 7.52 if fed96 == 48002
replace margin = 33.79 if fed96 == 48003
replace margin = 40.75 if fed96 == 48004
replace margin = 40.7 if fed96 == 48005
replace margin = 42.43 if fed96 == 48006
replace margin = 48.52 if fed96 == 48007
replace margin = 32.48 if fed96 == 48008
replace margin = 56.4 if fed96 == 48009
replace margin = 8.23 if fed96 == 48010
replace margin = 16.89 if fed96 == 48011
replace margin = 11.36 if fed96 == 48012
replace margin = 14.87 if fed96 == 48013
replace margin = 10.11 if fed96 == 48014
replace margin = 1.470001 if fed96 == 48015
replace margin = 46.54 if fed96 == 48016
replace margin = 45.27 if fed96 == 48017
replace margin = 49.07999 if fed96 == 48018
replace margin = 56.22 if fed96 == 48019
replace margin = 63.8 if fed96 == 48020
replace margin = 50.1 if fed96 == 48021
replace margin = 59.79 if fed96 == 48022
replace margin = 34.72 if fed96 == 48023
replace margin = 52.33 if fed96 == 48024
replace margin = 57.46 if fed96 == 48025
replace margin = 50.44 if fed96 == 48026
replace margin = 4.309998 if fed96 == 59001
replace margin = 39.29 if fed96 == 59002
replace margin = 27.63 if fed96 == 59003
replace margin = 40.35 if fed96 == 59004
replace margin = 25.81 if fed96 == 59005
replace margin = 53.68 if fed96 == 59006
replace margin = 20.56 if fed96 == 59007
replace margin = 35.61 if fed96 == 59008
replace margin = 53.04 if fed96 == 59009
replace margin = 52.85 if fed96 == 59010
replace margin = 29.75 if fed96 == 59011
replace margin = 25.21 if fed96 == 59012
replace margin = 13 if fed96 == 59013
replace margin = 40.71 if fed96 == 59014
replace margin = 17.11 if fed96 == 59015
replace margin = 38.91 if fed96 == 59016
replace margin = 20.3 if fed96 == 59017
replace margin = 35.41 if fed96 == 59018
replace margin = 54.09 if fed96 == 59019
replace margin = 2.369999 if fed96 == 59020
replace margin = 10.86 if fed96 == 59021
replace margin = 13.61 if fed96 == 59022
replace margin = 38.69 if fed96 == 59023
replace margin = 17.83 if fed96 == 59024
replace margin = 27.23 if fed96 == 59025
replace margin = 16.15 if fed96 == 59026
replace margin = 8.539997 if fed96 == 59027
replace margin = 26.2 if fed96 == 59028
replace margin = 13.47 if fed96 == 59029
replace margin = 7.34 if fed96 == 59030
replace margin = 5.600002 if fed96 == 59031
replace margin = 12.99 if fed96 == 59032
replace margin = 19.34 if fed96 == 59033
replace margin = 21.37 if fed96 == 59034
replace margin = .5299988 if fed96 == 60001
replace margin = 18.89 if fed96 == 61002
replace margin = 50.74 if fed96 == 62001

* Effective number of electoral parties by district

gen enep = .

replace enep = 2.530321 if fed96 == 10001
replace enep = 3.023929 if fed96 == 10002
replace enep = 2.514743 if fed96 == 10003
replace enep = 2.885178 if fed96 == 10004
replace enep = 1.960134 if fed96 == 10005
replace enep = 2.525182 if fed96 == 10006
replace enep = 2.444103 if fed96 == 10007
replace enep = 2.228311 if fed96 == 11001
replace enep = 2.463187 if fed96 == 11002
replace enep = 3.142393 if fed96 == 11003
replace enep = 2.533689 if fed96 == 11004
replace enep = 2.580422 if fed96 == 12001
replace enep = 2.967535 if fed96 == 12002
replace enep = 3.38133 if fed96 == 12003
replace enep = 3.260448 if fed96 == 12004
replace enep = 3.376089 if fed96 == 12005
replace enep = 3.417886 if fed96 == 12006
replace enep = 2.838201 if fed96 == 12007
replace enep = 3.614332 if fed96 == 12008
replace enep = 3.198895 if fed96 == 12009
replace enep = 2.546344 if fed96 == 12010
replace enep = 3.404476 if fed96 == 12011
replace enep = 2.571855 if fed96 == 13001
replace enep = 2.867122 if fed96 == 13002
replace enep = 2.887593 if fed96 == 13003
replace enep = 3.333565 if fed96 == 13004
replace enep = 3.224161 if fed96 == 13005
replace enep = 2.373605 if fed96 == 13006
replace enep = 2.785482 if fed96 == 13007
replace enep = 2.45802 if fed96 == 13008
replace enep = 2.77813 if fed96 == 13009
replace enep = 3.213242 if fed96 == 13010
replace enep = 2.300341 if fed96 == 24001
replace enep = 2.503016 if fed96 == 24002
replace enep = 2.32091 if fed96 == 24003
replace enep = 2.706987 if fed96 == 24004
replace enep = 2.504795 if fed96 == 24005
replace enep = 2.404048 if fed96 == 24006
replace enep = 3.098933 if fed96 == 24007
replace enep = 2.614131 if fed96 == 24008
replace enep = 2.37665 if fed96 == 24009
replace enep = 2.133949 if fed96 == 24010
replace enep = 2.713698 if fed96 == 24011
replace enep = 2.544988 if fed96 == 24012
replace enep = 2.710905 if fed96 == 24013
replace enep = 2.41854 if fed96 == 24014
replace enep = 3.224738 if fed96 == 24015
replace enep = 2.173086 if fed96 == 24016
replace enep = 2.522861 if fed96 == 24017
replace enep = 2.670806 if fed96 == 24018
replace enep = 2.663927 if fed96 == 24019
replace enep = 2.873054 if fed96 == 24020
replace enep = 2.537146 if fed96 == 24021
replace enep = 2.134217 if fed96 == 24022
replace enep = 2.891334 if fed96 == 24023
replace enep = 2.591709 if fed96 == 24024
replace enep = 2.981144 if fed96 == 24025
replace enep = 2.583539 if fed96 == 24026
replace enep = 2.555326 if fed96 == 24027
replace enep = 2.198157 if fed96 == 24028
replace enep = 2.429196 if fed96 == 24029
replace enep = 2.017461 if fed96 == 24030
replace enep = 1.766169 if fed96 == 24031
replace enep = 2.027009 if fed96 == 24032
replace enep = 2.473956 if fed96 == 24033
replace enep = 2.822734 if fed96 == 24034
replace enep = 2.628221 if fed96 == 24035
replace enep = 2.594666 if fed96 == 24036
replace enep = 2.654474 if fed96 == 24037
replace enep = 3.148358 if fed96 == 24038
replace enep = 2.594484 if fed96 == 24039
replace enep = 2.777553 if fed96 == 24040
replace enep = 3.083541 if fed96 == 24041
replace enep = 2.406473 if fed96 == 24042
replace enep = 2.325839 if fed96 == 24043
replace enep = 2.547915 if fed96 == 24044
replace enep = 1.497571 if fed96 == 24045
replace enep = 3.123194 if fed96 == 24046
replace enep = 2.703302 if fed96 == 24047
replace enep = 1.815275 if fed96 == 24048
replace enep = 3.014528 if fed96 == 24049
replace enep = 3.111868 if fed96 == 24050
replace enep = 3.068864 if fed96 == 24051
replace enep = 3.15051 if fed96 == 24052
replace enep = 2.420177 if fed96 == 24053
replace enep = 2.35323 if fed96 == 24054
replace enep = 3.152228 if fed96 == 24055
replace enep = 2.24659 if fed96 == 24056
replace enep = 2.334322 if fed96 == 24057
replace enep = 2.767823 if fed96 == 24058
replace enep = 2.292947 if fed96 == 24059
replace enep = 2.695704 if fed96 == 24060
replace enep = 2.820264 if fed96 == 24061
replace enep = 2.315476 if fed96 == 24062
replace enep = 2.747743 if fed96 == 24063
replace enep = 2.768115 if fed96 == 24064
replace enep = 1.774209 if fed96 == 24065
replace enep = 1.636922 if fed96 == 24066
replace enep = 2.242732 if fed96 == 24067
replace enep = 2.454983 if fed96 == 24068
replace enep = 2.529023 if fed96 == 24069
replace enep = 2.64285 if fed96 == 24070
replace enep = 2.46664 if fed96 == 24071
replace enep = 2.541805 if fed96 == 24072
replace enep = 2.66379 if fed96 == 24073
replace enep = 2.795407 if fed96 == 24074
replace enep = 2.534966 if fed96 == 24075
replace enep = 2.916133 if fed96 == 35001
replace enep = 2.788407 if fed96 == 35002
replace enep = 2.867287 if fed96 == 35003
replace enep = 2.57603 if fed96 == 35004
replace enep = 2.82767 if fed96 == 35005
replace enep = 2.061965 if fed96 == 35006
replace enep = 2.519413 if fed96 == 35007
replace enep = 2.787169 if fed96 == 35008
replace enep = 2.872062 if fed96 == 35009
replace enep = 2.981534 if fed96 == 35010
replace enep = 2.949717 if fed96 == 35011
replace enep = 2.107338 if fed96 == 35012
replace enep = 2.071225 if fed96 == 35013
replace enep = 2.582294 if fed96 == 35014
replace enep = 2.966298 if fed96 == 35015
replace enep = 3.011316 if fed96 == 35016
replace enep = 2.380934 if fed96 == 35017
replace enep = 3.038797 if fed96 == 35018
replace enep = 2.975692 if fed96 == 35019
replace enep = 2.939094 if fed96 == 35020
replace enep = 2.52308 if fed96 == 35021
replace enep = 2.817405 if fed96 == 35022
replace enep = 1.757143 if fed96 == 35023
replace enep = 1.97695 if fed96 == 35024
replace enep = 2.815577 if fed96 == 35025
replace enep = 3.141916 if fed96 == 35026
replace enep = 2.793834 if fed96 == 35027
replace enep = 2.975893 if fed96 == 35028
replace enep = 2.887093 if fed96 == 35029
replace enep = 2.900927 if fed96 == 35030
replace enep = 2.909108 if fed96 == 35031
replace enep = 3.310493 if fed96 == 35032
replace enep = 2.890832 if fed96 == 35033
replace enep = 2.98645 if fed96 == 35034
replace enep = 2.748144 if fed96 == 35035
replace enep = 2.98035 if fed96 == 35036
replace enep = 2.694415 if fed96 == 35037
replace enep = 2.95132 if fed96 == 35038
replace enep = 2.812916 if fed96 == 35039
replace enep = 3.118045 if fed96 == 35040
replace enep = 2.937068 if fed96 == 35041
replace enep = 2.923011 if fed96 == 35042
replace enep = 2.657476 if fed96 == 35043
replace enep = 2.983219 if fed96 == 35044
replace enep = 2.037051 if fed96 == 35045
replace enep = 2.1688 if fed96 == 35046
replace enep = 2.151831 if fed96 == 35047
replace enep = 2.74583 if fed96 == 35048
replace enep = 2.184194 if fed96 == 35049
replace enep = 2.974622 if fed96 == 35050
replace enep = 3.113121 if fed96 == 35051
replace enep = 2.997193 if fed96 == 35052
replace enep = 2.564494 if fed96 == 35053
replace enep = 2.51142 if fed96 == 35054
replace enep = 3.108609 if fed96 == 35055
replace enep = 2.374705 if fed96 == 35056
replace enep = 2.8834 if fed96 == 35057
replace enep = 3.303763 if fed96 == 35058
replace enep = 3.741344 if fed96 == 35059
replace enep = 2.836943 if fed96 == 35060
replace enep = 2.735287 if fed96 == 35061
replace enep = 3.214749 if fed96 == 35062
replace enep = 3.39354 if fed96 == 35063
replace enep = 3.19023 if fed96 == 35064
replace enep = 3.040865 if fed96 == 35065
replace enep = 3.366056 if fed96 == 35066
replace enep = 2.941486 if fed96 == 35067
replace enep = 2.459091 if fed96 == 35068
replace enep = 2.793683 if fed96 == 35069
replace enep = 2.765791 if fed96 == 35070
replace enep = 2.774966 if fed96 == 35071
replace enep = 2.80645 if fed96 == 35072
replace enep = 1.874935 if fed96 == 35073
replace enep = 1.95426 if fed96 == 35074
replace enep = 2.380651 if fed96 == 35075
replace enep = 1.561725 if fed96 == 35076
replace enep = 2.433244 if fed96 == 35077
replace enep = 2.962339 if fed96 == 35078
replace enep = 2.717984 if fed96 == 35079
replace enep = 2.936127 if fed96 == 35080
replace enep = 2.771101 if fed96 == 35081
replace enep = 2.764421 if fed96 == 35082
replace enep = 2.609182 if fed96 == 35083
replace enep = 2.499256 if fed96 == 35084
replace enep = 2.143752 if fed96 == 35085
replace enep = 3.637531 if fed96 == 35086
replace enep = 3.153674 if fed96 == 35087
replace enep = 2.280229 if fed96 == 35088
replace enep = 2.471326 if fed96 == 35089
replace enep = 2.770745 if fed96 == 35090
replace enep = 2.65377 if fed96 == 35091
replace enep = 2.016792 if fed96 == 35092
replace enep = 3.279541 if fed96 == 35093
replace enep = 3.007034 if fed96 == 35094
replace enep = 3.193677 if fed96 == 35095
replace enep = 2.65457 if fed96 == 35096
replace enep = 2.310965 if fed96 == 35097
replace enep = 2.887638 if fed96 == 35098
replace enep = 2.66647 if fed96 == 35099
replace enep = 1.879506 if fed96 == 35100
replace enep = 2.962979 if fed96 == 35101
replace enep = 2.609274 if fed96 == 35102
replace enep = 1.618922 if fed96 == 35103
replace enep = 3.464572 if fed96 == 46001
replace enep = 3.389852 if fed96 == 46002
replace enep = 2.942833 if fed96 == 46003
replace enep = 3.151137 if fed96 == 46004
replace enep = 3.09371 if fed96 == 46005
replace enep = 2.426238 if fed96 == 46006
replace enep = 2.806038 if fed96 == 46007
replace enep = 3.307595 if fed96 == 46008
replace enep = 2.318802 if fed96 == 46009
replace enep = 3.190864 if fed96 == 46010
replace enep = 2.723776 if fed96 == 46011
replace enep = 3.430909 if fed96 == 46012
replace enep = 3.404248 if fed96 == 46013
replace enep = 3.012269 if fed96 == 46014
replace enep = 2.349273 if fed96 == 47001
replace enep = 3.129501 if fed96 == 47002
replace enep = 3.034745 if fed96 == 47003
replace enep = 2.31302 if fed96 == 47004
replace enep = 3.035482 if fed96 == 47005
replace enep = 3.247386 if fed96 == 47006
replace enep = 2.712167 if fed96 == 47007
replace enep = 2.593012 if fed96 == 47008
replace enep = 3.160821 if fed96 == 47009
replace enep = 2.77055 if fed96 == 47010
replace enep = 2.222395 if fed96 == 47011
replace enep = 2.730972 if fed96 == 47012
replace enep = 2.88504 if fed96 == 47013
replace enep = 2.220186 if fed96 == 47014
replace enep = 2.543387 if fed96 == 48001
replace enep = 2.692295 if fed96 == 48002
replace enep = 2.726963 if fed96 == 48003
replace enep = 2.204343 if fed96 == 48004
replace enep = 2.368265 if fed96 == 48005
replace enep = 2.178784 if fed96 == 48006
replace enep = 2.125685 if fed96 == 48007
replace enep = 2.675404 if fed96 == 48008
replace enep = 1.901856 if fed96 == 48009
replace enep = 3.02585 if fed96 == 48010
replace enep = 2.559706 if fed96 == 48011
replace enep = 2.387364 if fed96 == 48012
replace enep = 2.713617 if fed96 == 48013
replace enep = 3.242911 if fed96 == 48014
replace enep = 2.592138 if fed96 == 48015
replace enep = 2.166123 if fed96 == 48016
replace enep = 2.080192 if fed96 == 48017
replace enep = 2.100622 if fed96 == 48018
replace enep = 1.911421 if fed96 == 48019
replace enep = 1.737324 if fed96 == 48020
replace enep = 2.11257 if fed96 == 48021
replace enep = 1.799591 if fed96 == 48022
replace enep = 2.33097 if fed96 == 48023
replace enep = 1.913561 if fed96 == 48024
replace enep = 1.901524 if fed96 == 48025
replace enep = 2.085739 if fed96 == 48026
replace enep = 3.244291 if fed96 == 59001
replace enep = 2.420378 if fed96 == 59002
replace enep = 2.40499 if fed96 == 59003
replace enep = 2.490224 if fed96 == 59004
replace enep = 3.023282 if fed96 == 59005
replace enep = 1.917021 if fed96 == 59006
replace enep = 2.910211 if fed96 == 59007
replace enep = 2.37055 if fed96 == 59008
replace enep = 2.028668 if fed96 == 59009
replace enep = 1.89035 if fed96 == 59010
replace enep = 3.034609 if fed96 == 59011
replace enep = 3.341242 if fed96 == 59012
replace enep = 3.146332 if fed96 == 59013
replace enep = 2.326083 if fed96 == 59014
replace enep = 2.743952 if fed96 == 59015
replace enep = 2.46261 if fed96 == 59016
replace enep = 2.869656 if fed96 == 59017
replace enep = 2.437238 if fed96 == 59018
replace enep = 1.939867 if fed96 == 59019
replace enep = 2.627982 if fed96 == 59020
replace enep = 3.218914 if fed96 == 59021
replace enep = 3.194386 if fed96 == 59022
replace enep = 2.390894 if fed96 == 59023
replace enep = 2.573163 if fed96 == 59024
replace enep = 2.462262 if fed96 == 59025
replace enep = 3.600235 if fed96 == 59026
replace enep = 3.180877 if fed96 == 59027
replace enep = 2.920029 if fed96 == 59028
replace enep = 3.308408 if fed96 == 59029
replace enep = 2.839397 if fed96 == 59030
replace enep = 3.001505 if fed96 == 59031
replace enep = 3.392396 if fed96 == 59032
replace enep = 3.222295 if fed96 == 59033
replace enep = 3.151857 if fed96 == 59034
replace enep = 3.450244 if fed96 == 60001
replace enep = 3.119468 if fed96 == 61002
replace enep = 1.92907 if fed96 == 62001


*******************************
** INCUMBENT PARTY REELECTED **
*******************************

gen reelected = .

replace reelected = 1 if fed96 == 10001
replace reelected = 0 if fed96 == 10002
replace reelected = 1 if fed96 == 10003
replace reelected = 1 if fed96 == 10004
replace reelected = 1 if fed96 == 10005
replace reelected = 1 if fed96 == 10006
replace reelected = 1 if fed96 == 10007
replace reelected = 1 if fed96 == 11001
replace reelected = 1 if fed96 == 11002
replace reelected = 1 if fed96 == 11003
replace reelected = 1 if fed96 == 11004
replace reelected = 0 if fed96 == 12001
replace reelected = 1 if fed96 == 12002
replace reelected = 1 if fed96 == 12003
replace reelected = 1 if fed96 == 12004
replace reelected = 0 if fed96 == 12005
replace reelected = 1 if fed96 == 12006
replace reelected = 1 if fed96 == 12007
replace reelected = 1 if fed96 == 12008
replace reelected = 1 if fed96 == 12009
replace reelected = 0 if fed96 == 12010
replace reelected = 0 if fed96 == 12011
replace reelected = 1 if fed96 == 13001
replace reelected = 0 if fed96 == 13002
replace reelected = 1 if fed96 == 13003
replace reelected = 1 if fed96 == 13004
replace reelected = 1 if fed96 == 13005
replace reelected = 0 if fed96 == 13006
replace reelected = 1 if fed96 == 13007
replace reelected = 1 if fed96 == 13008
replace reelected = 1 if fed96 == 13009
replace reelected = 0 if fed96 == 13010
replace reelected = 1 if fed96 == 24001
replace reelected = 1 if fed96 == 24002
replace reelected = 1 if fed96 == 24003
replace reelected = 1 if fed96 == 24004
replace reelected = 1 if fed96 == 24005
replace reelected = 0 if fed96 == 24006
replace reelected = 1 if fed96 == 24007
replace reelected = 1 if fed96 == 24008
replace reelected = 1 if fed96 == 24009
replace reelected = 1 if fed96 == 24010
replace reelected = 1 if fed96 == 24011
replace reelected = 1 if fed96 == 24012
replace reelected = 1 if fed96 == 24013
replace reelected = 1 if fed96 == 24014
replace reelected = 1 if fed96 == 24015
replace reelected = 1 if fed96 == 24016
replace reelected = 1 if fed96 == 24017
replace reelected = 0 if fed96 == 24018
replace reelected = 0 if fed96 == 24019
replace reelected = 1 if fed96 == 24020
replace reelected = 0 if fed96 == 24021
replace reelected = 0 if fed96 == 24022
replace reelected = 1 if fed96 == 24023
replace reelected = 1 if fed96 == 24024
replace reelected = 1 if fed96 == 24025
replace reelected = 1 if fed96 == 24026
replace reelected = 1 if fed96 == 24027
replace reelected = 1 if fed96 == 24028
replace reelected = 1 if fed96 == 24029
replace reelected = 1 if fed96 == 24030
replace reelected = 1 if fed96 == 24031
replace reelected = 1 if fed96 == 24032
replace reelected = 1 if fed96 == 24033
replace reelected = 1 if fed96 == 24034
replace reelected = 1 if fed96 == 24035
replace reelected = 0 if fed96 == 24036
replace reelected = 1 if fed96 == 24037
replace reelected = 1 if fed96 == 24038
replace reelected = 1 if fed96 == 24039
replace reelected = 1 if fed96 == 24040
replace reelected = 0 if fed96 == 24041
replace reelected = 1 if fed96 == 24042
replace reelected = 1 if fed96 == 24043
replace reelected = 1 if fed96 == 24044
replace reelected = 1 if fed96 == 24045
replace reelected = 1 if fed96 == 24046
replace reelected = 1 if fed96 == 24047
replace reelected = 1 if fed96 == 24048
replace reelected = 1 if fed96 == 24049
replace reelected = 0 if fed96 == 24050
replace reelected = 1 if fed96 == 24051
replace reelected = 0 if fed96 == 24052
replace reelected = 1 if fed96 == 24053
replace reelected = 1 if fed96 == 24054
replace reelected = 1 if fed96 == 24055
replace reelected = 1 if fed96 == 24056
replace reelected = 1 if fed96 == 24057
replace reelected = 1 if fed96 == 24058
replace reelected = 1 if fed96 == 24059
replace reelected = 1 if fed96 == 24060
replace reelected = 1 if fed96 == 24061
replace reelected = 1 if fed96 == 24062
replace reelected = 1 if fed96 == 24063
replace reelected = 1 if fed96 == 24064
replace reelected = 1 if fed96 == 24065
replace reelected = 1 if fed96 == 24066
replace reelected = 1 if fed96 == 24067
replace reelected = 0 if fed96 == 24068
replace reelected = 0 if fed96 == 24069
replace reelected = 1 if fed96 == 24070
replace reelected = 1 if fed96 == 24071
replace reelected = 1 if fed96 == 24072
replace reelected = 1 if fed96 == 24073
replace reelected = 1 if fed96 == 24074
replace reelected = 1 if fed96 == 24075
replace reelected = 1 if fed96 == 35001
replace reelected = 1 if fed96 == 35002
replace reelected = 1 if fed96 == 35003
replace reelected = 1 if fed96 == 35004
replace reelected = 1 if fed96 == 35005
replace reelected = 1 if fed96 == 35006
replace reelected = 1 if fed96 == 35007
replace reelected = 1 if fed96 == 35008
replace reelected = 1 if fed96 == 35009
replace reelected = 1 if fed96 == 35010
replace reelected = 1 if fed96 == 35011
replace reelected = 1 if fed96 == 35012
replace reelected = 1 if fed96 == 35013
replace reelected = 1 if fed96 == 35014
replace reelected = 1 if fed96 == 35015
replace reelected = 1 if fed96 == 35016
replace reelected = 1 if fed96 == 35017
replace reelected = 1 if fed96 == 35018
replace reelected = 1 if fed96 == 35019
replace reelected = 1 if fed96 == 35020
replace reelected = 1 if fed96 == 35021
replace reelected = 1 if fed96 == 35022
replace reelected = 1 if fed96 == 35023
replace reelected = 1 if fed96 == 35024
replace reelected = 1 if fed96 == 35025
replace reelected = 1 if fed96 == 35026
replace reelected = 1 if fed96 == 35027
replace reelected = 1 if fed96 == 35028
replace reelected = 1 if fed96 == 35029
replace reelected = 1 if fed96 == 35030
replace reelected = 1 if fed96 == 35031
replace reelected = 1 if fed96 == 35032
replace reelected = 1 if fed96 == 35033
replace reelected = 1 if fed96 == 35034
replace reelected = 1 if fed96 == 35035
replace reelected = 1 if fed96 == 35036
replace reelected = 1 if fed96 == 35037
replace reelected = 1 if fed96 == 35038
replace reelected = 1 if fed96 == 35039
replace reelected = 0 if fed96 == 35040
replace reelected = 1 if fed96 == 35041
replace reelected = 1 if fed96 == 35042
replace reelected = 1 if fed96 == 35043
replace reelected = 1 if fed96 == 35044
replace reelected = 0 if fed96 == 35045
replace reelected = 1 if fed96 == 35046
replace reelected = 1 if fed96 == 35047
replace reelected = 1 if fed96 == 35048
replace reelected = 1 if fed96 == 35049
replace reelected = 1 if fed96 == 35050
replace reelected = 1 if fed96 == 35051
replace reelected = 1 if fed96 == 35052
replace reelected = 1 if fed96 == 35053
replace reelected = 1 if fed96 == 35054
replace reelected = 1 if fed96 == 35055
replace reelected = 1 if fed96 == 35056
replace reelected = 1 if fed96 == 35057
replace reelected = 1 if fed96 == 35058
replace reelected = 1 if fed96 == 35059
replace reelected = 1 if fed96 == 35060
replace reelected = 1 if fed96 == 35061
replace reelected = 1 if fed96 == 35062
replace reelected = 1 if fed96 == 35063
replace reelected = 1 if fed96 == 35064
replace reelected = 1 if fed96 == 35065
replace reelected = 1 if fed96 == 35066
replace reelected = 1 if fed96 == 35067
replace reelected = 1 if fed96 == 35068
replace reelected = 1 if fed96 == 35069
replace reelected = 0 if fed96 == 35070
replace reelected = 1 if fed96 == 35071
replace reelected = 1 if fed96 == 35072
replace reelected = 1 if fed96 == 35073
replace reelected = 1 if fed96 == 35074
replace reelected = 1 if fed96 == 35075
replace reelected = 1 if fed96 == 35076
replace reelected = 1 if fed96 == 35077
replace reelected = 1 if fed96 == 35078
replace reelected = 1 if fed96 == 35079
replace reelected = 1 if fed96 == 35080
replace reelected = 1 if fed96 == 35081
replace reelected = 1 if fed96 == 35082
replace reelected = 1 if fed96 == 35083
replace reelected = 1 if fed96 == 35084
replace reelected = 1 if fed96 == 35085
replace reelected = 1 if fed96 == 35086
replace reelected = 1 if fed96 == 35087
replace reelected = 1 if fed96 == 35088
replace reelected = 1 if fed96 == 35089
replace reelected = 1 if fed96 == 35090
replace reelected = 1 if fed96 == 35091
replace reelected = 1 if fed96 == 35092
replace reelected = 1 if fed96 == 35093
replace reelected = 1 if fed96 == 35094
replace reelected = 1 if fed96 == 35095
replace reelected = 1 if fed96 == 35096
replace reelected = 1 if fed96 == 35097
replace reelected = 0 if fed96 == 35098
replace reelected = 1 if fed96 == 35099
replace reelected = 1 if fed96 == 35100
replace reelected = 1 if fed96 == 35101
replace reelected = 0 if fed96 == 35102
replace reelected = 1 if fed96 == 35103
replace reelected = 1 if fed96 == 46001
replace reelected = 1 if fed96 == 46002
replace reelected = 1 if fed96 == 46003
replace reelected = 1 if fed96 == 46004
replace reelected = 1 if fed96 == 46005
replace reelected = 0 if fed96 == 46006
replace reelected = 1 if fed96 == 46007
replace reelected = 1 if fed96 == 46008
replace reelected = 1 if fed96 == 46009
replace reelected = 1 if fed96 == 46010
replace reelected = 1 if fed96 == 46011
replace reelected = 1 if fed96 == 46012
replace reelected = 1 if fed96 == 46013
replace reelected = 1 if fed96 == 46014
replace reelected = 1 if fed96 == 47001
replace reelected = 1 if fed96 == 47002
replace reelected = 0 if fed96 == 47003
replace reelected = 1 if fed96 == 47004
replace reelected = 1 if fed96 == 47005
replace reelected = 1 if fed96 == 47006
replace reelected = 1 if fed96 == 47007
replace reelected = 0 if fed96 == 47008
replace reelected = 1 if fed96 == 47009
replace reelected = 0 if fed96 == 47010
replace reelected = 1 if fed96 == 47011
replace reelected = 1 if fed96 == 47012
replace reelected = 1 if fed96 == 47013
replace reelected = 1 if fed96 == 47014
replace reelected = 1 if fed96 == 48001
replace reelected = 0 if fed96 == 48002
replace reelected = 1 if fed96 == 48003
replace reelected = 1 if fed96 == 48004
replace reelected = 1 if fed96 == 48005
replace reelected = 1 if fed96 == 48006
replace reelected = 1 if fed96 == 48007
replace reelected = 1 if fed96 == 48008
replace reelected = 1 if fed96 == 48009
replace reelected = 1 if fed96 == 48010
replace reelected = 1 if fed96 == 48011
replace reelected = 1 if fed96 == 48012
replace reelected = 1 if fed96 == 48013
replace reelected = 1 if fed96 == 48014
replace reelected = 1 if fed96 == 48015
replace reelected = 1 if fed96 == 48016
replace reelected = 1 if fed96 == 48017
replace reelected = 1 if fed96 == 48018
replace reelected = 1 if fed96 == 48019
replace reelected = 1 if fed96 == 48020
replace reelected = 1 if fed96 == 48021
replace reelected = 1 if fed96 == 48022
replace reelected = 1 if fed96 == 48023
replace reelected = 1 if fed96 == 48024
replace reelected = 1 if fed96 == 48025
replace reelected = 1 if fed96 == 48026
replace reelected = 1 if fed96 == 59001
replace reelected = 1 if fed96 == 59002
replace reelected = 1 if fed96 == 59003
replace reelected = 1 if fed96 == 59004
replace reelected = 1 if fed96 == 59005
replace reelected = 1 if fed96 == 59006
replace reelected = 0 if fed96 == 59007
replace reelected = 1 if fed96 == 59008
replace reelected = 1 if fed96 == 59009
replace reelected = 1 if fed96 == 59010
replace reelected = 1 if fed96 == 59011
replace reelected = 1 if fed96 == 59012
replace reelected = 1 if fed96 == 59013
replace reelected = 1 if fed96 == 59014
replace reelected = 1 if fed96 == 59015
replace reelected = 1 if fed96 == 59016
replace reelected = 1 if fed96 == 59017
replace reelected = 1 if fed96 == 59018
replace reelected = 1 if fed96 == 59019
replace reelected = 0 if fed96 == 59020
replace reelected = 1 if fed96 == 59021
replace reelected = 1 if fed96 == 59022
replace reelected = 1 if fed96 == 59023
replace reelected = 1 if fed96 == 59024
replace reelected = 1 if fed96 == 59025
replace reelected = 1 if fed96 == 59026
replace reelected = 1 if fed96 == 59027
replace reelected = 1 if fed96 == 59028
replace reelected = 1 if fed96 == 59029
replace reelected = 1 if fed96 == 59030
replace reelected = 1 if fed96 == 59031
replace reelected = 1 if fed96 == 59032
replace reelected = 1 if fed96 == 59033
replace reelected = 1 if fed96 == 59034
replace reelected = 0 if fed96 == 60001
replace reelected = 1 if fed96 == 61002
replace reelected = 1 if fed96 == 62001
   

***************************
** INDEPENDENT VARIABLES **
***************************

* Response date

gen surveydate = mdy(cpsmonth,cpsday,cpsyear)

format %tdMon_DD,_CCYY surveydate

gen edate = 20001127

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = (electiondate - surveydate) - 1 // Substract 1 to correct for election date

* Gender

gen male = cpsrgen

recode male (5=0)

label define gender 0 "Female" 1 "Male"
label values male gender

* Age

gen age = cpsage

recode age (9999=.)

replace age = 2000 - age

replace age = . if age < 17

* Education

gen education = cpsm3

recode education (98=.)
recode education (99=.)

* Interest for election

gen interest = cpsb4

recode interest (98=.)
recode interest (99=.)

* Party identification (district)

gen pidstatus_district = .

replace pidstatus_district = 9999 if cpsk1a == . & cpsk4a == .
replace pidstatus_district = 9999 if cpsk3a == 1 & cpsk4a == 98 | cpsk3a == 1 & cpsk4a == 99
replace pidstatus_district = 9999 if cpsk1a == 98 & cpsk4a == 98 | cpsk1a == 98 & cpsk4a == 99 | cpsk1a == 99 & cpsk4a == 98 | cpsk1a == 99 & cpsk4a == 99 | cpsk1a == 0 & cpsk4a == 99

replace pidstatus_district = 2 if cpsk1a == 0 & cpsk3a == 5 | cpsk1a == 0 & cpsk3a == 8

replace pidstatus_district = 3 if cpsk1a == district_outcome & pidstatus_district!=2 & pidstatus_district!=9999
replace pidstatus_district = 3 if cpsk4a == district_outcome & pidstatus_district!=2 & pidstatus_district!=9999

replace pidstatus_district = 1 if cpsk1a!=district_outcome & cpsk1a!=. & pidstatus_district!=2 & pidstatus_district!=3 & pidstatus_district!=9999
replace pidstatus_district = 1 if cpsk4a!=district_outcome & cpsk4a!=. & pidstatus_district!=2 & pidstatus_district!=3 & pidstatus_district!=9999

gen winner_leaner = 1 if cpsk3b == district_outcome & pidstatus_district == 9999
gen loser_leaner = 1 if cpsk3b!=district_outcome & cpsk3b!=8 & cpsk3b!=9 & pidstatus_district == 9999

replace pidstatus_district = 2 if cpsk3b == 7 & pidstatus_district == 9999

replace pidstatus_district = . if pidstatus_district == 9999
 
label define pidstatus 1 "Loser PID" 2 "No PID" 3 "Winner PID"
label values pidstatus_district pidstatus

* Party identification scale (district)

gen pidscale_district = .

replace pidscale_district = 1 if pidstatus_district == 1 & cpsk2a == 1
replace pidscale_district = 2 if pidstatus_district == 1 & cpsk2a == 3
replace pidscale_district = 3 if pidstatus_district == 1 & cpsk2a == 5 | loser_leaner == 1
replace pidscale_district = 4 if pidstatus_district == 2
replace pidscale_district = 5 if pidstatus_district == 3 & cpsk2a == 5 | winner_leaner == 1
replace pidscale_district = 6 if pidstatus_district == 3 & cpsk2a == 3
replace pidscale_district = 7 if pidstatus_district == 3 & cpsk2a == 1

label define pidscale 1 "Strong loser PID" 2 "Moderate loser PID" 3 "Weak loser PID" 4 "No PID" 5 "Weak winner PID" 6 "Moderate winner PID" 7 "Strong winner PID"
label values pidscale_district pidscale

* TV news attentiveness

gen tv = cpsb1

recode tv (98=.)
recode tv (99=.)

recode tv (.=-99)

* Press news attentiveness

gen press = cpsb2

recode press (98=.)
recode press (99=.)

recode press (.=-99)

* Radio news attentiveness

gen radio = cpsb3

recode radio (98=.)
recode radio (99=.)

recode radio (.=-99)

* News attentiveness index

egen news = rowmax(tv press radio)

recode news (-99=.)

* Name of NDP leader - Correct answer (Alexa McDonough) = 1, Incorrect answer = 0

gen ndpleader = cpslead1 // NDP leader

recode ndpleader (5=0) // Recode "any other answer" as incorrect answer
recode ndpleader (8=0) // Recode "don't know" as incorrect answer
recode ndpleader (9=.) // Recode "refused" as missing data

* Name of PC leader - Correct answer (Joe Clark) = 1, Incorrect answer = 0

gen pcleader = cpslead2 // PC leader

recode pcleader (5=0) // Recode "any other answer" as incorrect answer
recode pcleader (8=0) // Recode "don't know" as incorrect answer
recode pcleader (9=.) // Recode "refused" as missing data

* Name of Alliance leader - Correct answer (Stockwell Day) = 1, Incorrect answer = 0

gen allianceleader = cpslead3 // Alliance leader

recode allianceleader (5=0) // Recode "any other answer" as incorrect answer
recode allianceleader (8=0) // Recode "don't know" as incorrect answer
recode allianceleader (9=.) // Recode "refused" as missing data

* Name of LPC leader - Correct answer (Jean Chrétien) = 1, Incorrect answer = 0

gen lpcleader = cpslead5 // LPC leader

recode lpcleader (5=0) // Recode "any other answer" as incorrect answer
recode lpcleader (8=0) // Recode "don't know" as incorrect answer
recode lpcleader (9=.) // Recode "refused" as missing data

* Name of the provincial premier/government leader - Correct answer (Brian Tobin/Beaton Tulk in Newfoundland, Patrick Binns in Prince Edward Island, John Hamm in Nova Scotia, Bernard Lord in New Brunswick, Lucien Bouchard in Quebec, Mike Harris in Ontario, Gary Doer in Manitoba, Roy Romanow in Saskatchewan, Ralph Klein in Alberta, Ujjal Dosanjh in British Columbia, Pat Duncan in Yukon, Stephen Kakfwi in Northwest Territories, Paul Okalik in Nunavut) = 1, Incorrect answer = 0

gen premier_leader = cpsl12 // Premier

recode premier_leader (10=1) if province == 10 // Premier of Newfoundland: correct answer
recode premier_leader (11=1) if province == 11 // Premier of Prince Edward Island: correct answer
recode premier_leader (12=1) if province == 12 // Premier of Nova Scotia: correct answer
recode premier_leader (13=1) if province == 13 // Premier of New Brunswick: correct answer
recode premier_leader (24=1) if province == 24 // Premier of Quebec: correct answer
recode premier_leader (35=1) if province == 35 // Premier of Ontario: correct answer
recode premier_leader (46=1) if province == 46 // Premier of Manitoba: correct answer
recode premier_leader (47=1) if province == 47 // Premier of Saskatchewan: correct answer
recode premier_leader (48=1) if province == 48 // Premier of Alberta: correct answer
recode premier_leader (59=1) if province == 59 // Premier of British Columbia: correct answer
recode premier_leader (60=1) if province == 60 // Premier of Yukon: correct answer
recode premier_leader (61=1) if province == 61 // Premier of Northwest Territories: correct answer
recode premier_leader (62=1) if province == 61 // Premier of Nunavut: correct answer
recode premier_leader (98=0) // Recode "don't know" as incorrect answer
recode premier_leader (99=.) // Recode "refused" as missing data

recode premier_leader (10=0) if province!=10 & premier_leader!=. // Premier of Newfoundland: incorrect answer
recode premier_leader (11=0) if province!=11 & premier_leader!=. // Premier of Prince Edward Island: incorrect answer
recode premier_leader (12=0) if province!=12 & premier_leader!=. // Premier of Nova Scotia: incorrect answer
recode premier_leader (13=0) if province!=13 & premier_leader!=. // Premier of New Brunswick: incorrect answer
recode premier_leader (24=0) if province!=24 & premier_leader!=. // Premier of Quebec: incorrect answer
recode premier_leader (35=0) if province!=35 & premier_leader!=. // Premier of Ontario: incorrect answer
recode premier_leader (46=0) if province!=46 & premier_leader!=. // Premier of Manitoba: incorrect answer
recode premier_leader (47=0) if province!=47 & premier_leader!=. // Premier of Saskatchewan: incorrect answer
recode premier_leader (48=0) if province!=48 & premier_leader!=. // Premier of Alberta: incorrect answer
recode premier_leader (59=0) if province!=59 & premier_leader!=. // Premier of British Columbia: incorrect answer
recode premier_leader (60=0) if province!=60 & premier_leader!=. // Premier of Yukon: incorrect answer
recode premier_leader (61=0) if province!=61 & premier_leader!=. // Premier of Northwest Territories: incorrect answer
recode premier_leader (62=0) if province!=62 & premier_leader!=. // Premier of Nunavut: incorrect answer

* Name of the Minister of Finance of Canada - Correct answer (Paul Martin) = 1, Incorrect answer = 0

gen financeminister = cpsl11 // Minister of Finance of Canada

recode financeminister (5=0) // Recode "any other answer" as incorrect answer
recode financeminister (8=0) // Recode "don't know" as incorrect answer
recode financeminister (9=.) // Recode "refused" as missing data

* Name of the Prime Minister of Canada at the time of the Free Trade Agreement with the United States - Correct answer (Brian Mulroney) = 1, Incorrect answer = 0

gen ftapm = cpsl13 // Prime Minister of Canada at the time of FTA

recode ftapm (5=0) // Recode "any other answer" as incorrect answer
recode ftapm (8=0) // Recode "don't know" as incorrect answer
recode ftapm (9=.) // Recode "refused" as missing data

* Capital of the United States - Correct answer (Washington, D.C.) = 1, Incorrect answer = 0

gen uscapital = cpsl14 // Capital of United States

recode uscapital (5=0) // Recode "any other answer" as incorrect answer
recode uscapital (8=0) // Recode "don't know" as incorrect answer
recode uscapital (9=.) // Recode "refused" as missing data

* Party promising a single tax rate for people earning less than one hundred thousand dollars a year - Correct answer (Alliance) = 1, Incorrect answer = 0

gen singletaxrate = cpsf13 // Single tax rate

recode singletaxrate (3=0) // Recode "Alliance and any other mention" as incorrect answer
recode singletaxrate (5=0) // Recode "any other mention" as incorrect answer
recode singletaxrate (7=0) // Recode "no, don't remember" as incorrect answer
recode singletaxrate (8=0) // Recode "don't know" as incorrect answer
recode singletaxrate (9=.) // Recode "refused" as missing data

* Party promising a national prescription drug plan - Correct answer (NDP) = 1, Incorrect answer = 0

gen prescription = cpsprom2 // National prescription drug plan

recode prescription (3=0) // Recode "NDP and another party" as incorrect answer
recode prescription (5=0) // Recode "other answers" as incorrect answer
recode prescription (7=0) // Recode "no, don't remember" as incorrect answer
recode prescription (8=0) // Recode "don't know" as incorrect answer
recode prescription (9=.) // Recode "refused" as missing data

* Party promising a law to fight criminal biker gangs/anti-gang law - Correct answer (BQ and Alliance) = 1, Incorrect answer = 0

gen bikers = cpsprom3 // Law to fight criminal biker gangs

recode bikers (2=1) // Recode "Alliance" as correct answer
recode bikers (3=1) // Recode "Bloc québécois and the Alliance" as correct answer

recode bikers (4=0) // Recode "Bloc québécois and a party other than the Alliance" as incorrect answer
recode bikers (5=0) // Recode "Alliance canadienne and a party other than the Bloc québécois" as incorrect answer
recode bikers (6=0) // Recode "other answers" as incorrect answer
recode bikers (8=0) // Recode "don't know" as incorrect answer
recode bikers (9=.) // Recode "refused" as missing data

* Party promising a law to pay back the debt in 25 years - Correct answer (CPC) = 1, Incorrect answer = 0

gen debt = cpsprom4 // Law to pay back the debt in 25 years

recode debt (3=0) // Recode "Conservative Party and another party" as incorrect answer
recode debt (5=0) // Recode "other answers" as incorrect answer
recode debt (8=0) // Recode "don't know" as incorrect answer
recode debt (9=.) // Recode "refused" as missing data

* Party promising to use half of the surplus to cut taxes and pay down the debt and half to spend on health care and social programs - Correct answer (LPC) = 1, Incorrect answer = 0

gen surplus = cpsprom5 // Half of the surplus uses

recode surplus (3=0) // Recode "Liberal Party and another party" as incorrect answer
recode surplus (5=0) // Recode "other answers" as incorrect answer
recode surplus (8=0) // Recode "don't know" as incorrect answer
recode surplus (9=.) // Recode "refused" as missing data

* Political knowledge index

gen knowledge = ndpleader + pcleader + allianceleader + lpcleader + premier_leader + financeminister + ftapm + uscapital + singletaxrate + prescription + bikers + debt + surplus // Political knowledge index

* Political discussion

gen discussion = cpsb8a

recode discussion (8=.)
recode discussion (9=.)

replace discussion = 30 if discussion == 1
replace discussion = 20 if discussion == 3
replace discussion = 10 if discussion == 5

replace discussion = 2 if discussion == 30
replace discussion = 1 if discussion == 20
replace discussion = 0 if discussion == 10

* Main source of information

gen network_main = 1 if cpsl4 == 5 | cpsl4 == 6

replace network_main = 0 if cpsl4!=5 & cpsl4!=6
replace network_main = . if cpsl4 == 8
replace network_main = . if cpsl4 == 9


*********************************
** DISTRICT-LEVEL EXPECTATIONS **
*********************************

* Generate variable identifying incomplete answers (BQ in Quebec only)

gen pcchance = cpsi1a
gen lpcchance = cpsi1b
gen ndpchance = cpsi1c
gen alliancechance = cpsi1d
gen bqchance = cpsi1e

recode pcchance lpcchance ndpchance alliancechance bqchance (996=0)
recode pcchance lpcchance ndpchance alliancechance bqchance (997=.)
recode pcchance lpcchance ndpchance alliancechance bqchance (998=.)
recode pcchance lpcchance ndpchance alliancechance bqchance (999=.)

gen complete_qc = 0 if pcchance == . & province == 24 | lpcchance == . & province == 24 | ndpchance == . & province == 24 | alliancechance ==. & province == 24 | bqchance ==. & province == 24
replace complete_qc = 1 if pcchance!=. & lpcchance!=. & ndpchance!=. & alliancechance!=. & province == 24 & bqchance!=. & province == 24

gen complete_roc = 0 if pcchance == . & province!=24 | lpcchance == . & province!=24 | ndpchance == . & province!=24 | alliancechance == . & province!=24
replace complete_roc = 1 if pcchance!=. & lpcchance!=. & ndpchance!=. & province!=24 & alliancechance!=. & province!=24

gen complete = max(complete_qc,complete_roc)

* Generate value of 1 if the expectation for one candidate is higher or equal to the expectations for at least one other candidate

gen pc_qc = 1 if pcchance >= lpcchance & pcchance >= ndpchance & pcchance >= alliancechance & pcchance >= bqchance & province == 24 & complete == 1
gen lpc_qc = 1 if lpcchance >= pcchance & lpcchance >= ndpchance & lpcchance >= alliancechance & lpcchance >= bqchance & province == 24 & complete == 1
gen ndp_qc = 1 if ndpchance >= pcchance & ndpchance >= lpcchance & ndpchance >= alliancechance & ndpchance >= bqchance & province == 24 & complete == 1
gen alliance_qc = 1 if alliancechance >= pcchance & alliancechance >= lpcchance & alliancechance >= ndpchance & alliancechance >= bqchance & province == 24 & complete == 1
gen bq_qc = 1 if bqchance >= pcchance & bqchance >= lpcchance & bqchance >= ndpchance & bqchance >= alliancechance & province == 24 & complete == 1
gen oth_qc = 1 if pcchance == 0 & lpcchance == 0 & ndpchance == 0 & alliancechance == 0 & bqchance == 0 & province == 24 & complete == 1

gen pc_roc = 1 if pcchance >= lpcchance & pcchance >= ndpchance & pcchance >= alliancechance & province!=24 & complete == 1
gen lpc_roc = 1 if lpcchance >= pcchance & lpcchance >= ndpchance & lpcchance >= alliancechance & province!=24 & complete == 1
gen ndp_roc = 1 if ndpchance >= pcchance & ndpchance >= lpcchance & ndpchance >= alliancechance & province!=24 & complete == 1
gen alliance_roc = 1 if alliancechance >= pcchance & alliancechance >= lpcchance & alliancechance >= ndpchance & province!=24 & complete == 1
gen oth_roc = 1 if pcchance == 0 & lpcchance == 0 & ndpchance == 0 & alliancechance == 0 & province!=24 & complete == 1

gen pc = max(pc_qc,pc_roc) if complete == 1
gen lpc = max(lpc_qc,lpc_roc) if complete == 1
gen ndp = max(ndp_qc,ndp_roc) if complete == 1
gen alliance = max(alliance_qc,alliance_roc) if complete == 1
gen bq = bq_qc if complete == 1
gen oth = max(oth_qc,oth_roc) if complete == 1

replace pc = . if oth == 1 & complete == 1
replace lpc = . if oth == 1 & complete == 1
replace ndp = . if oth == 1 & complete == 1
replace alliance = . if oth == 1 & complete == 1
replace bq = . if oth == 1 & complete == 1

* Generate variable for ambiguous forecasts

gen ambiguous = .

replace ambiguous = 99 if pc == lpc & pc!=. & complete == 1 | pc == ndp & pc!=. & complete == 1 | pc == alliance & pc!=. & complete == 1 | pc == bq & pc!=. & complete == 1
replace ambiguous = 99 if lpc == pc & lpc!=. & complete == 1 | lpc == ndp & lpc!=. & complete == 1 | lpc == alliance & lpc!=. & complete == 1 | lpc == bq & lpc!=. & complete == 1
replace ambiguous = 99 if ndp == pc & ndp!=. & complete == 1 | ndp == lpc & ndp!=. & complete == 1 | ndp == alliance & ndp!=. & complete == 1 | ndp == bq & ndp!=. & complete == 1
replace ambiguous = 99 if alliance == pc & alliance!=. & complete == 1 | alliance == lpc & alliance!=. & complete == 1 | alliance == ndp & alliance!=. & complete == 1 | alliance == bq & alliance!=. & complete == 1
replace ambiguous = 99 if bq == pc & bq!=. & complete == 1 | bq == lpc & bq!=. & complete == 1 | bq == ndp & bq!=. & complete == 1 | bq == alliance & bq!=. & complete == 1

gen amb = 1 if ambiguous == 99 & complete == 1

* Generate value of 0 for lower standardized expectations

replace pc = 0 if pc!=1 & complete == 1
replace lpc = 0 if lpc!=1 & complete == 1
replace ndp = 0 if ndp!=1 & complete == 1
replace alliance = 0 if alliance!=1 & complete == 1
replace bq = 0 if bq!=1 & complete == 1
replace oth = 0 if oth!=1 & complete == 1

* Forecasts (1 = LPC, 2 = BQ, 3 = Reform/Alliance, 4 = PC, 5 = NDP, 97 = other, 99 = ambiguous)

gen forecast = .

replace forecast = 4 if pc == 1 & complete == 1
replace forecast = 1 if lpc == 1 & complete == 1
replace forecast = 5 if ndp == 1 & complete == 1
replace forecast = 3 if alliance == 1 & complete == 1
replace forecast = 2 if bq == 1 & complete == 1
replace forecast = 97 if oth == 1 & complete == 1
replace forecast = 99 if ambiguous == 99 & complete == 1

* Identify correct and ambiguous forecasts

gen correct_district = 0 if forecast!=district_outcome & complete == 1
replace correct_district = 1 if forecast == district_outcome & forecast!=99 & complete == 1

replace correct_district = 0 if forecast == 99 & pc!=1 & district_outcome == 4 & complete == 1
replace correct_district = 0 if forecast == 99 & lpc!=1 & district_outcome == 1 & complete == 1
replace correct_district = 0 if forecast == 99 & ndp!=1 & district_outcome == 5 & complete == 1
replace correct_district = 0 if forecast == 99 & alliance!=1 & district_outcome == 3 & complete == 1
replace correct_district = 0 if forecast == 99 & bq!=1 & district_outcome == 2 & complete == 1
replace correct_district = 0 if forecast == 99 & oth!=1 & district_outcome == 97 & complete == 1

replace correct_district = 0 if (cpsi1a == 997 | cpsi1a == 998) & (cpsi1b == 997 | cpsi1b == 998) & (cpsi1c == 997 | cpsi1c == 998) & (cpsi1d == 997 | cpsi1d == 998) & (cpsi1e == 997 | cpsi1e == 998)

replace correct_district = 99 if forecast == 99 & pc == 1 & district_outcome == 4 & complete == 1
replace correct_district = 99 if forecast == 99 & lpc == 1 & district_outcome == 1 & complete == 1
replace correct_district = 99 if forecast == 99 & ndp == 1 & district_outcome == 5 & complete == 1
replace correct_district = 99 if forecast == 99 & alliance == 1 & district_outcome == 3 & complete == 1
replace correct_district = 99 if forecast == 99 & bq == 1 & district_outcome == 2 & complete == 1
replace correct_district = 99 if forecast == 99 & oth == 1 & district_outcome == 97 & complete == 1

* Generate dichotomous variable (treat ambiguous forecasts as incorrect)

gen correct_district_d = correct_district

replace correct_district_d = 0 if correct_district_d == 99
replace correct_district_d = 1 if correct_district_d == 1


**********
** SAVE **
**********

save "ca2000_ces.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts

melogit correct_district_d discussion pidscale_district interest news knowledge age i.male education time enep i.reelected || fed96: , or
estimates table, star(.05 .01 .001)

tab correct_district_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_district_d "District winner (DV)"
label variable discussion "Discussion"
label variable pidscale_district "District PID"
label variable interest "Interest"
label variable news "News attentiveness"
label variable knowledge "Political knowledge"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"
label variable enep "ENEP"
label variable margin "Margin"
label variable reelected "Reelected"

estpost tabstat correct_district_d discussion pidscale_district interest news knowledge age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "ca2000_ces_summary_district.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.1f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2000 Canadian federal election (CES), district level") replace

eststo clear


*************************
** ADDITIONAL ANALYSES **
*************************

* Regression analysis

melogit correct_district_d i.network_main discussion pidscale_district interest news knowledge age i.male education time enep i.reelected || fed96: , or
estimates table, star(.05 .01 .001)

log close